<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="/component/layui/css/layui.css">
    <style>
        label.required:after { /* 给红色的必填项打红色星号（文字后）如果打前面用before*/
            content: ' *';
            color: red;
        }

        .layui-input {
            height: 50px;
        }

        .layui-form-label {
            height: 50px;
            line-height: 45px;
            padding: 0px;
        }

        .layui-form-select dl {
            position: absolute;
            left: 0;
            top: 51px;
            height: 240px;
        }

        .submit-btn-container .layui-btn, .pear-btn {
            height: 45px;
            width: 130px;
            font-size: 20px;
        }

        .pear-btn i {
            font-size: 20px;
        }
    </style>
</head>
<body>
<div class="main-container">
    <form class="layui-form" action="" style="font-size: 16px;">
        <div class="layui-form-item">
            <label class="layui-form-label" style="display:none">id</label>
            <div class="layui-input-block" style="display:none">
                <input type="text" th:value="${id}" id="id" name="id" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">ip地址</label>
            <div class="layui-input-block">
                <input type="text" id="ip" th:value="${ip}" name="ip" required="" placeholder="请输入ip地址"
                       lay-verify="required" lay-reqtext="请输入ip地址" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">机柜编号</label>
            <div class="layui-input-block">
                <input type="text" id="number" th:value="${number}" name="number" required=""
                       lay-verify="required" lay-reqtext="请输入机柜编号" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">层</label>
            <div class="layui-input-block">
                <input type="number" name="layer" placeholder="请输入层" th:value="${numberOfLayers}"
                       lay-verify="required" lay-reqtext="请输入层" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">列</label>
            <div class="layui-input-block">
                <input type="number" name="column" placeholder="请输入列"  th:value="${numberOfColumns}"
                       lay-verify="required" lay-reqtext="请输入列" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-form-item submit-btn-container">
                <div class="layui-input-block" style="display: flex;flex-direction: row;justify-content: center;">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="host-save">
                        <i class="layui-icon layui-icon-file-b"></i>
                        保存
                    </button>
                    <button type="reset" class="layui-btn layui-btn-primary" style="margin-left: 25px">重置
                    </button>
                </div>
            </div>
        </div>
    </form>
</div>
<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit(host-save)', function (data) {
            let index = layer.load();
            $.ajax({
                url: '/host/edit/save',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    layer.close(index);
                    if (result.code == 200) {
                        layer.msg(result.message, {icon: 1, time: 2000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        });
                    } else {
                        layer.msg(result.message, {icon: 2, time: 2000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>
